<template>
	<div class="orderDetails">
    <!-- 车辆库存明细 -->
    <div :style="{
        'margin-top': '20px',
        border: '1px solid #f2f2f2'
      }">
      <div :style="{
          'background':' #f2f2f2',
          'height': '32px',
          'line-height': '32px',
          'padding-left': '20px',
          'margin-bottom': '20px',
        }">车辆基本信息</div>
      <FormPanel
        :list="formList"
        :cols="4"
        labelWidth='100'
        :isSubmitBtn="false"
        :formType="type"
      />
    </div>
    <div :style="{
        'margin-top': '20px',
        border: '1px solid #f2f2f2'
      }">
      <div :style="{
          'background':' #f2f2f2',
          'height': '32px',
          'line-height': '32px',
          'padding-left': '20px',
          'margin-bottom': '20px',
        }">车辆库存信息</div>
      <FormPanel
        :list="formList1"
        :cols="4"
        labelWidth='100'
        :isSubmitBtn="false"
        :formType="type"
      />
    </div>
    <div :style="{
        'margin-top': '20px',
        border: '1px solid #f2f2f2'
      }">
      <div :style="{
          'background':' #f2f2f2',
          'height': '32px',
          'line-height': '32px',
          'padding-left': '20px',
          'margin-bottom': '20px',
        }">车辆价格信息</div>
      <FormPanel
        :list="formList2"
        :cols="4"
        labelWidth='100'
        :isSubmitBtn="false"
        :formType="type"
      />
    </div>
		<div class="upWard">
			<el-button size="small"  @click="closeDialog">返回</el-button>
		</div>
	</div>
</template>

<script>
import { getVsStockDetailById } from '@/api/vehicle/stockmanage/InventoryMaintenance';
import moment from 'moment'
import { dictionary } from '@/utils/dictMixin';
export default {
  name: 'orderDetails',
  mixins: [dictionary],
  props: {
    type: {
      type: String,
      default: 'show'
    },
    rowData : {
      type: Object,
      default: () => ({})
    }
  },
	data (){
		return {
      formList: this.createFormList(),
      formList1: this.createFormList1(),
      formList2: this.createFormList2(),
      whiteListOfFieldName: [
        'factoryDate',
        'firstStockInDate',
        'latestStockInDate',
        'latestStockOutDate',
        'productDate',
        'purchaseDate'
      ]
		}
  },
  mounted (){
    this.init();
  },
	methods: {
    init (){
      // console.log(this.type)
      // console.log(this.rowData)
      this.inventoryDetail(this.rowData);
    },
    async inventoryDetail (row){  //根据父组件传递的ID获取详细数据并赋值
      let res = await getVsStockDetailById(row.vsStockId);
  		if(res.resultCode == 200){
        this.formList.forEach(x => {
          if (this.whiteListOfFieldName.includes(x.fieldName)) {
            let date = res.data[x.fieldName];
            x.initialValue = date ? moment(Number(date)).format('YYYY-MM-DD HH:mm:ss') : date;
          }else{
            x.initialValue = res.data[x.fieldName];
          }
        });
        this.formList1.forEach(x => {
          if (this.whiteListOfFieldName.includes(x.fieldName)) {
            let date = res.data[x.fieldName];
            x.initialValue = date ? moment(Number(date)).format('YYYY-MM-DD HH:mm:ss') : date;
          }else{
            x.initialValue = res.data[x.fieldName];
          }
        });
        this.formList2.forEach(x => {
          if (this.whiteListOfFieldName.includes(x.fieldName)) {
            let date = res.data[x.fieldName];
            x.initialValue = date ? moment(Number(date)).format('YYYY-MM-DD HH:mm:ss') : date;
          }else{
            x.initialValue = res.data[x.fieldName];
          }
        });
  		}
    },
		createFormList () {
			return [
				{
          type: 'INPUT',
          label: '品牌',
          fieldName: 'brandName',
          initialValue: ''
        },
        {
          type: 'INPUT',
          label: '车系,',
          fieldName: 'seriesName',
          initialValue: ''
        },
        {
          type: 'INPUT',
          label: '车型',
          fieldName: 'modelName',
          initialValue: ''
        },
        {
          type: 'INPUT',
          label: '配置',
          fieldName: 'packageName',
          initialValue: ''
        },
        {
          type: 'INPUT',
          label: '颜色',
          fieldName: 'colorName',
          initialValue: ''
        },
        {
          type: 'INPUT',
          label: '产品代码',
          fieldName: 'productCode',
          initialValue: ''
        },
        {
          type: 'INPUT',
          label: '产品名称',
          fieldName: 'productName',
          initialValue: ''
        },
        {
          type: 'INPUT',
          label: 'VIN号',
          fieldName: 'vin',
          initialValue: ''
        },
        {
          type: 'INPUT',
          label: '钥匙号',
          fieldName: 'keyNo',
          initialValue: ''
        },
        {
          type: 'INPUT',
          label: '合格证号',
          fieldName: 'certificateNumber',
          initialValue: ''
        },
        {
          type: 'INPUT',
          label: '发动机号',
          fieldName: 'engineNo',
          initialValue: ''
        },
        {
          type: 'INPUT',
          label: '保修手册号',
          fieldName: 'warrantyManualNo', //TODO:warrantyManualNo
          initialValue: ''
        },
        {
          type: 'INPUT',
          label: '排放标准',
          fieldName: 'dischargeStandard',
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '排气量',
          fieldName: 'exhaustQuantity',
          initialValue: ''
        },
        {
          type: 'INPUT',
          label: '生产厂商',
          fieldName: 'productingArea', //TODO: productingArea
          initialValue: ''
        },
        {
          type: 'INPUT',
          label: '生产日期', //TODO: factoryDate
          fieldName: 'productDate',
          initialValue: ''
        },
        {
          type: 'INPUT',
          label: '出厂日期',
          fieldName: 'factoryDate', //TODO: factoryDate
          initialValue: ''
        },
        {
          type: 'INPUT',
          label: '备注',
          fieldName: 'remark',
          initialValue: ''
        }
			]
    },
    createFormList1 () {
			return [
        // 车辆库存信息
        {
          type: 'INPUT',
          label: '仓库名称',
          fieldName: 'storageName',
          placeholder: '',
          initialValue: ''
        },
        {
          type: 'SELECT',
          label: '库存状态',
          fieldName: 'ownStockStatus',
          placeholder: '',
          initialValue: '',
          itemList: this.createDictList('1413')
        },
        {
          type: 'SELECT',
          label: '配车状态',
          fieldName: 'dispatchedStatus',
          placeholder: '',
          initialValue: '',
          itemList: this.createDictList('1414')
        },
        {
          type: 'SELECT',
          label: '是否锁定',
          fieldName: 'isLock',
          initialValue: '',
          placeholder: '',
          itemList: this.createDictList('1004')
        },
        {
          type: 'SELECT',
          label: '质损状态',
          fieldName: 'trafficMarStatus', //TODO:trafficMarStatus
          initialValue: '',
          placeholder: '',
          itemList: this.createDictList('1040')
        },
        {
          type: 'SELECT',
          label: '试乘试驾车',
          fieldName: 'isTestDrive',
          initialValue: '',
          placeholder: '',
          itemList: this.createDictList('1004')
        },
        {
          type: 'SELECT',
          label: '是否外借',
          fieldName: 'isBorrowed',
          initialValue: '',
          placeholder: '',
          itemList: this.createDictList('1004')
        },
        {
          type: 'SELECT',
          label: '是否交车',
          fieldName: 'isDeliver',
          initialValue: '',
          placeholder: '',
          itemList: [{text:'是',value: 1}, {text:'否',value:2}]
        },
        {
          type: 'SELECT',
          label: '是否直销',
          fieldName: 'isDirect',
          initialValue: '',
          placeholder: '',
          itemList: this.createDictList('1004')
        },
        {
          type: 'INPUT',
          label: '库位',
          fieldName: 'storagePositionCode',
          initialValue: '',
          placeholder: '',
        },
        {
          type: 'SELECT',
          label: '入库类型',
          fieldName: 'entryType',
          initialValue: '',
          placeholder: '',
          itemList: this.createDictList('1317') //TODO: 数据有误，字典来源不一致
        },
        {
          type: 'SELECT',
          label: '出库类型',
          fieldName: 'deliveryType',
          initialValue: '',
          placeholder: '',
          itemList: this.createDictList('1318') //TODO: 数据有误，字典来源不一致
        },
        {
          type: 'INPUT',
          label: '首次入库日期',
          fieldName: 'firstStockInDate',
          initialValue: '',
          placeholder: '',
        },
        {
          type: 'INPUT',
          label: '入库日期',
          fieldName: 'latestStockInDate',
          initialValue: '',
          placeholder: '',

        },
        {
          type: 'INPUT',
          label: '出库日期',
          fieldName: 'latestStockOutDate',
          initialValue: '',
          placeholder: '',
        }
			]
    },
    createFormList2 () {
			return [
        {
          type: 'INPUT',
          label: '采购日期',
          fieldName: 'purchaseDate',
          initialValue: '',
          placeholder: '',
        },
        {
          type: 'INPUT',
          label: '采购价格',
          fieldName: 'purchasePrice',
          initialValue: '',
          placeholder: '',
        },
        {
          type: 'INPUT',
          label: '车厂指导价',
          fieldName: 'oemDirectivePrice',
          initialValue: '',
          placeholder: '',
        },
        {
          type: 'INPUT',
          label: '销售指导价',
          fieldName: 'directivePrice',
          initialValue: '',
          placeholder: '',
        }
			]
		},
    closeDialog (){ //返回上层
      this.$emit('close', false);
    }
	}

}
</script>

<style scoped="scoped" lang="less">
.upWard{
	margin-top: 15px;
	text-align: center;
}
</style>
